package com.yuanfeng.job.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.job.dto.CategoryMonthlySalesDTO;
import com.yuanfeng.job.entity.JobStatisticsCatEntity;
import com.yuanfeng.job.mapper.JobStatisticsCatMapper;
import com.yuanfeng.job.service.JobStatisticsCatService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class JobStatisticsCatServiceImpl extends ServiceImpl<JobStatisticsCatMapper, JobStatisticsCatEntity>
    implements JobStatisticsCatService {

    @Override
    public ResponseResult insertOdbStatisticsCat(CategoryMonthlySalesDTO param) {
        List<CategoryMonthlySalesDTO> realList = this.baseMapper.queryCatTurnoverReal(param);
        List<CategoryMonthlySalesDTO> selfList = this.baseMapper.queryCatTurnoverSelf(param);
        for (CategoryMonthlySalesDTO real : realList) {
            for (CategoryMonthlySalesDTO self : selfList) {

                if (real.getFirstCatId().equals(self.getFirstCatId())) {
                    real.setCatTurnoverSelf(self.getCatTurnoverSelf());
                    if (real.getFirstCatId() != null) {

                        switch (real.getFirstCatId()) {
                            case 999:
                                real.setFirstCatName("其它分类");
                                break;
                            case 1000:
                                real.setFirstCatName("地方特产");
                                break;
                            case 1006080236:
                                real.setFirstCatName("粮油调味");
                                break;
                            case 1006080309:
                                real.setFirstCatName("乳品冲饮");
                                break;
                            case 1006080325:
                                real.setFirstCatName("茗茶名酒");
                                break;
                            case 1006080506:
                                real.setFirstCatName("休闲食品");
                                break;
                            case 1006080654:
                                real.setFirstCatName("滋补营养");
                                break;
                            case 1006080730:
                                real.setFirstCatName("生鲜果蔬");
                                break;
                        }
                    }


                    if (self.getCatTurnoverSelf() != null) {
                        real.setCatTurnoverAll(real.getCatTurnoverReal().add(self.getCatTurnoverSelf()));
                    }

                    JobStatisticsCatEntity entity=new JobStatisticsCatEntity();
                    BeanUtils.copyProperties(real,entity);
                    this.baseMapper.insert(entity);
                }

            }
        }

        return ResponseResult.success(BizCodeEnume.OPERATION_SUCCESSFUL.getMsg());
    }
}




